%load_ext pretty_jupyter

Introduction

In this notebook we focus on interactive components. We will demonstrate their usage in normal code cells and sometimes also in Jinja Markdown cells.

If your desired interactive package is not mentioned here, it will still most likely work with Pretty Jupyter.

Visualization

Plotly

import plotly.express as px

fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])

We can display the figure like this. Note that the specification of renderer is sometimes not necessary.

fig.show(renderer="notebook_connected")
%%jmd
[//]: # (-.-|m { input: true })

We can also use it as HTML in Jinja Markdown. Although some environments refuse to render it, it is present in the output page.

{{ fig.to_html(include_plotlyjs=False, full_html=False, default_height=400, default_width=600) }}

We can also use it as HTML in Jinja Markdown. Although some environments refuse to render it, it is present in the output page.

Highcharts

Highcharts is another interactive plotting package.

The example below was taken directly from their website.

from highcharts import Highchart
chart = Highchart()

chart.set_options('chart', {'inverted': True})

options = {
    'title': {
        'text': 'Atmosphere Temperature by Altitude'
    },
    'subtitle': {
        'text': 'According to the Standard Atmosphere Model'
    },
    'xAxis': {
        'reversed': False,
        'title': {
            'enabled': True,
            'text': 'Altitude'
        },
        'labels': {
            'formatter': 'function () {\
                return this.value + "km";\
            }'
        },
        'maxPadding': 0.05,
        'showLastLabel': True
    },
    'yAxis': {
        'title': {
            'text': 'Temperature'
        },
        'labels': {
            'formatter': "function () {\
                return this.value + '°';\
            }"
        },
        'lineWidth': 2
    },
    'legend': {
        'enabled': False
    },
    'tooltip': {
        'headerFormat': '<b>{series.name}</b><br/>',
        'pointFormat': '{point.x} km: {point.y}°C'
    }
}

chart.set_dict_options(options)
data =  [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1], 
[50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]
chart.add_data_set(data, 'spline', 'Temperature', marker={'enabled': False}) 

chart

Tables

This chapter shows how to have interactive tables in Pretty Jupyter.

ITables

For this demonstration, we use itables package.

We need to call itables.init_notebook_mode before using itables.show.

import itables
import pandas as pd
itables.init_notebook_mode()

data = pd.DataFrame({"col1": [1, 2, 3, 4], "col2": [5, 6, 7, 8 ]})

itables.show(data)
col1 col2
Loading... (need help?)